package com.htsk.city.services.admin.aspect;

import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.json.JSONUtil;
import com.htsk.city.services.admin.annotation.GetLoginUser;
import com.htsk.city.services.core.constant.HttpStatus;
import com.htsk.city.services.core.dao.SysUserDao;
import com.htsk.city.services.core.domain.Role;
import com.htsk.city.services.core.domain.SysUser;
import com.htsk.city.services.core.exception.ServiceException;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import javax.annotation.Resource;
import java.util.List;

@Component
public class LoginUserAspect implements HandlerMethodArgumentResolver {

    @Resource
    private SysUserDao sysUserDao;

    /**
     *
     * @param parameter
     * @return
     */
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.hasParameterAnnotation(GetLoginUser.class);
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        return JSONUtil.toBean(StpUtil.getLoginIdAsString(), SysUser.class);
    }
}
